
package RoleLevel

import(
	"fmt"
	"sanguo/node/table/excel"
	"sanguo/node/table/excel/table"
	"strconv"

	"github.com/tealeg/xlsx"
)

func readInt32(v string) int32 {
	return int32(readFloat(v))
}

func readFloat(v string) float64 {
	vv,err := strconv.ParseFloat(v,64)
	if nil != err {
		panic(err)
	}
	return vv
}

func readBool(str string) bool {
    b, err := strconv.ParseBool(str)
	if nil != err {
		panic(err)
	}
    return b
}

func readStr(v string) string {
	return fmt.Sprintf("%s",v)
}

type RoleLevel struct {
	ID int32
	Exp int32
	Attack int32
	AttackPower int32
	Defenses int32
	DefensesPower int32
	HitPoint int32
	HPPower int32
	ElementalDefenses int32
	ElementalDefensesPower int32
	ArmorPoiseHealth int32
	PoiseDamage int32
	PoiseDamagePower int32
	MovementSpeed int32
	MovementSpeedPower int32
	AwakenEnergy int32
	AwakenEnergyGain int32
	AwakenEnergyGainSpeed int32
	AwakenEnergyCost int32
	AwakenEnergyLessCost int32
	MusouEnergy int32
	MusouEnergyGain int32
	MusouEnergyGainSpeed int32
	CritChance int32
	CritPower int32
	CritDamage int32
	DamagePower int32
	DefensesReduction int32
	FireAttack int32
	FireAttackPower int32
	IceAttack int32
	IceAttackPower int32
	LightningAttack int32
	LightningAttackPower int32
	AttackPowerToAir int32
	AttackPowerToFall int32
	AttackPowerToHumanGrass int32
	AttackPowerToInfernal int32
	AttackPowerToBoss int32
	PhysicalResistance int32
	ElementalResistance int32
	MusouAttack int32
	MusouAttackPower int32
	AwakenAttack int32
	AwakenAttackPower int32
}

type Table struct {
	IDMap map[int32]*RoleLevel
	tmpIDMap map[int32]*RoleLevel
	xlsxName string
}

var Table_ Table

func getIdxByName(names *xlsx.Row, name string) int {
	for i, v := range names.Cells {
		if v.String() == name {
			return i
		}
	}
	return -1
}

func init() {
	Table_.xlsxName = "RoleLevel.xlsx"
	Table_.IDMap = make(map[int32]*RoleLevel)
	Table_.tmpIDMap = make(map[int32]*RoleLevel)

	table.AddTable(&Table_)
}


func (this *Table) Load(path string) {

	excel.EmptyFunc()

    xlFile, err := xlsx.OpenFile(path + this.xlsxName)
    if err != nil {
		panic(err)
    }

    sheet := xlFile.Sheets[0]
    names := sheet.Rows[1]
    rows  := sheet.Rows[3:]

    for _,row := range(rows) {
    	if len(row.Cells) > 0 && row.Cells[0].String() != "" {
    		ele := &RoleLevel{}
    	
		ele.ID = readInt32(row.Cells[getIdxByName(names, "ID")].String())
		this.tmpIDMap[ele.ID] = ele
		ele.Exp = readInt32(row.Cells[getIdxByName(names, "Exp")].String())
		ele.Attack = readInt32(row.Cells[getIdxByName(names, "Attack")].String())
		ele.AttackPower = readInt32(row.Cells[getIdxByName(names, "AttackPower")].String())
		ele.Defenses = readInt32(row.Cells[getIdxByName(names, "Defenses")].String())
		ele.DefensesPower = readInt32(row.Cells[getIdxByName(names, "DefensesPower")].String())
		ele.HitPoint = readInt32(row.Cells[getIdxByName(names, "HitPoint")].String())
		ele.HPPower = readInt32(row.Cells[getIdxByName(names, "HPPower")].String())
		ele.ElementalDefenses = readInt32(row.Cells[getIdxByName(names, "ElementalDefenses")].String())
		ele.ElementalDefensesPower = readInt32(row.Cells[getIdxByName(names, "ElementalDefensesPower")].String())
		ele.ArmorPoiseHealth = readInt32(row.Cells[getIdxByName(names, "ArmorPoiseHealth")].String())
		ele.PoiseDamage = readInt32(row.Cells[getIdxByName(names, "PoiseDamage")].String())
		ele.PoiseDamagePower = readInt32(row.Cells[getIdxByName(names, "PoiseDamagePower")].String())
		ele.MovementSpeed = readInt32(row.Cells[getIdxByName(names, "MovementSpeed")].String())
		ele.MovementSpeedPower = readInt32(row.Cells[getIdxByName(names, "MovementSpeedPower")].String())
		ele.AwakenEnergy = readInt32(row.Cells[getIdxByName(names, "AwakenEnergy")].String())
		ele.AwakenEnergyGain = readInt32(row.Cells[getIdxByName(names, "AwakenEnergyGain")].String())
		ele.AwakenEnergyGainSpeed = readInt32(row.Cells[getIdxByName(names, "AwakenEnergyGainSpeed")].String())
		ele.AwakenEnergyCost = readInt32(row.Cells[getIdxByName(names, "AwakenEnergyCost")].String())
		ele.AwakenEnergyLessCost = readInt32(row.Cells[getIdxByName(names, "AwakenEnergyLessCost")].String())
		ele.MusouEnergy = readInt32(row.Cells[getIdxByName(names, "MusouEnergy")].String())
		ele.MusouEnergyGain = readInt32(row.Cells[getIdxByName(names, "MusouEnergyGain")].String())
		ele.MusouEnergyGainSpeed = readInt32(row.Cells[getIdxByName(names, "MusouEnergyGainSpeed")].String())
		ele.CritChance = readInt32(row.Cells[getIdxByName(names, "CritChance")].String())
		ele.CritPower = readInt32(row.Cells[getIdxByName(names, "CritPower")].String())
		ele.CritDamage = readInt32(row.Cells[getIdxByName(names, "CritDamage")].String())
		ele.DamagePower = readInt32(row.Cells[getIdxByName(names, "DamagePower")].String())
		ele.DefensesReduction = readInt32(row.Cells[getIdxByName(names, "DefensesReduction")].String())
		ele.FireAttack = readInt32(row.Cells[getIdxByName(names, "FireAttack")].String())
		ele.FireAttackPower = readInt32(row.Cells[getIdxByName(names, "FireAttackPower")].String())
		ele.IceAttack = readInt32(row.Cells[getIdxByName(names, "IceAttack")].String())
		ele.IceAttackPower = readInt32(row.Cells[getIdxByName(names, "IceAttackPower")].String())
		ele.LightningAttack = readInt32(row.Cells[getIdxByName(names, "LightningAttack")].String())
		ele.LightningAttackPower = readInt32(row.Cells[getIdxByName(names, "LightningAttackPower")].String())
		ele.AttackPowerToAir = readInt32(row.Cells[getIdxByName(names, "AttackPowerToAir")].String())
		ele.AttackPowerToFall = readInt32(row.Cells[getIdxByName(names, "AttackPowerToFall")].String())
		ele.AttackPowerToHumanGrass = readInt32(row.Cells[getIdxByName(names, "AttackPowerToHumanGrass")].String())
		ele.AttackPowerToInfernal = readInt32(row.Cells[getIdxByName(names, "AttackPowerToInfernal")].String())
		ele.AttackPowerToBoss = readInt32(row.Cells[getIdxByName(names, "AttackPowerToBoss")].String())
		ele.PhysicalResistance = readInt32(row.Cells[getIdxByName(names, "PhysicalResistance")].String())
		ele.ElementalResistance = readInt32(row.Cells[getIdxByName(names, "ElementalResistance")].String())
		ele.MusouAttack = readInt32(row.Cells[getIdxByName(names, "MusouAttack")].String())
		ele.MusouAttackPower = readInt32(row.Cells[getIdxByName(names, "MusouAttackPower")].String())
		ele.AwakenAttack = readInt32(row.Cells[getIdxByName(names, "AwakenAttack")].String())
		ele.AwakenAttackPower = readInt32(row.Cells[getIdxByName(names, "AwakenAttackPower")].String())

		}
    }

    this.IDMap = this.tmpIDMap
 
}

